package com.rth.vedio.domain.handler.vedio;

import com.rth.common.enums.VedioTypeEnum;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class VedioTypeHandlerFactory implements InitializingBean {


    @Resource
    List<VedioTypeHandler> vedioTypeHandlers;
    Map<VedioTypeEnum, VedioTypeHandler> handlerMap = new HashMap<>();

    public VedioTypeHandler getVedioTypeHandler(int code) {
        VedioTypeEnum vedioTypeEnum = VedioTypeEnum.getVedioTypeEnum(code);
        return handlerMap.get(vedioTypeEnum);
    }


    @Override
    public void afterPropertiesSet() throws Exception {
        vedioTypeHandlers.forEach(handler -> {
            handlerMap.put(handler.getVedioType(),handler);
        });
    }
}
